//
//  LSYBook.m
//  LSYReader
//
//  Created by sam on 2018/3/23.
//  Copyright © 2018年 okwei. All rights reserved.
//

#import "LSYBook.h"

@implementation LSYBook


+ (instancetype)book:(HTMLElement *)el rule:(LSYParseModel *)rule relativeUrl:(NSURL *)url{
    LSYBook *book = [[LSYBook alloc] init];
    book.bookName = [rule getElText:el rule:rule.bookName relativeUrl:url];
    book.bookIcon = [rule getElText:el rule:rule.bookIcon relativeUrl:url];
    book.bookUrl = [rule getElText:el rule:rule.bookUrl relativeUrl:url];
    book.bookDesc = [rule getElText:el rule:rule.bookDesc relativeUrl:url];
    book.bookAuthor = [rule getElText:el rule:rule.bookAuthor relativeUrl:url];
    book.bookCategory = [rule getElText:el rule:rule.bookCategory relativeUrl:url];
    book.bookUpdateTime = [rule getElText:el rule:rule.bookUpdateTime relativeUrl:url];
    book.bookLastChapterName = [rule getElText:el rule:rule.bookLastChapterName relativeUrl:url];
    book.rule = rule;
    return book;
}

- (BOOL)isTheSameBook:(LSYBook *)book {
    if ([self.bookName isEqualToString:book.bookName] && ([self.bookAuthor  rangeOfString:book.bookAuthor].location != NSNotFound || [book.bookAuthor rangeOfString:self.bookAuthor].location != NSNotFound)) {
        return YES;
    }
    return NO;
}

- (void)updateBook:(LSYBook *)book {
    self.bookIcon = book.bookIcon;
    self.bookUrl  = book.bookUrl;
    self.bookCategory  = book.bookCategory;
    self.bookUpdateTime= book.bookUpdateTime;
    self.bookLastChapterName = book.bookLastChapterName;
    self.bookDesc = book.bookDesc;
    self.chapters = book.chapters;
    self.rule = book.rule;
}

@end
